﻿CREATE PROCEDURE [dbo].[GetPublishers]
	@orderBy varchar(100)
AS
	select	*
	from	PublisherView as pv
	order   by
		case
			when @orderBy = 'AuthorCount' then (RANK() over (order by pv.AuthorCount))
			when @orderBy = 'AuthorCount desc' then (RANK() over (order by pv.AuthorCount desc))
			when @orderBy = 'BookCount' then (RANK() over (order by pv.BookCount))
			when @orderBy = 'BookCount desc' then (RANK() over (order by pv.BookCount desc))
			when @orderBy = 'City' then (RANK() over (order by pv.City))
			when @orderBy = 'City desc' then (RANK() over (order by pv.City desc))
			when @orderBy = 'PublisherName' then (RANK() over (order by pv.PublisherName))
			when @orderBy = 'PublisherName desc' then (RANK() over (order by pv.PublisherName desc))
			else (RANK() over (order by pv.PublisherName))
		end;
RETURN 0